<script setup lang="ts">
import {reactive, ref} from 'vue'
const dialogFormVisible = ref(false)
const formLabelWidth = '140px'

const form = reactive({
  name: '',
  isAdmin: '',
  password: '',
})

const isCreate = ref<Boolean>(true)
const msgText = ref<string>("")
const initAndShow = (id: number) => {
  dialogFormVisible.value = true
  if (id) {
    isCreate.value = false
    msgText.value = "更新"
  } else {
    isCreate.value = true
    msgText.value = "创建"
  }
}
defineExpose({
  initAndShow,
})
</script>

<template>
  <el-dialog v-model="dialogFormVisible" title="更改用户信息">
    <el-form :model="form">
      <el-form-item label="用户名称" :label-width="formLabelWidth" prop="name">
        <el-input v-model="form.name" autocomplete="off"/>
      </el-form-item>
      <el-form-item label="用户密码" :label-width="formLabelWidth" prop="password">
        <el-input v-model="form.password" autocomplete="off"/>
      </el-form-item>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取消</el-button>
        <el-button type="primary" @click="dialogFormVisible = false">
          提交
        </el-button>
      </span>
    </template>
  </el-dialog>
</template>

<style scoped>
.el-button--text {
  margin-right: 15px;
}

.el-select {
  width: 300px;
}

.el-input {
  width: 300px;
}

.dialog-footer button:first-child {
  margin-right: 10px;
}
</style>